package thread;

import org.w3c.dom.ls.LSOutput;

import java.util.*;

public class SyncApiDemo2 {
    public static void main(String[] args) {
       // Collection<Integer>c=new ArrayList<>();
        //Collection< Integer>c=new LinkedSet<>();
        //Collection<Integer>c=new HashSet<>();
        Collection<Integer> c=Collections.synchronizedList(new ArrayList<>());
        Thread t1=new Thread(){
            public void run(){
                for(int i=0;i<1000;i++){
                    c.add(i);
                }
            }
        };
        Thread t2=new Thread(){
            public void run(){
                for(int i=0;i<2000;i++){
                    c.add(i);
                }
            }
        };
        t1.start();
        t2.start();
        try{
            Thread.sleep(50);
        }catch(InterruptedException e){

    }
        System.out.println(c.toArray().length);
}}


